package com.hzlx.exception.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.exception.domain.ProductionAnomalies;
import com.hzlx.exception.service.IProductionAnomaliesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产异常记录Controller
 * 
 * @author dk
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/production")
public class ProductionAnomaliesController extends BaseController
{
    @Autowired
    private IProductionAnomaliesService productionAnomaliesService;

    /**
     * 查询生产异常记录列表
     */
    @RequiresPermissions("production-service:exception:list")
    @GetMapping("/exception/list")
    public TableDataInfo list(ProductionAnomalies productionAnomalies)
    {
        startPage();
        List<ProductionAnomalies> list = productionAnomaliesService.selectProductionAnomaliesList(productionAnomalies);
        return getDataTable(list);
    }

    /**
     * 导出生产异常记录列表
     */
    @RequiresPermissions("production-service:exception:export")
    @Log(title = "生产异常记录", businessType = BusinessType.EXPORT)
    @PostMapping("/exception/export")
    public void export(HttpServletResponse response, ProductionAnomalies productionAnomalies)
    {
        List<ProductionAnomalies> list = productionAnomaliesService.selectProductionAnomaliesList(productionAnomalies);
        ExcelUtil<ProductionAnomalies> util = new ExcelUtil<ProductionAnomalies>(ProductionAnomalies.class);
        util.exportExcel(response, list, "生产异常记录数据");
    }

    /**
     * 获取生产异常记录详细信息
     */
    @RequiresPermissions("production-service:exception:query")
    @GetMapping(value = "/exception/{anomalyId}")
    public AjaxResult getInfo(@PathVariable("anomalyId") Long anomalyId)
    {
        return success(productionAnomaliesService.selectProductionAnomaliesByAnomalyId(anomalyId));
    }

    /**
     * 新增生产异常记录
     */
    @RequiresPermissions("production-service:exception:add")
    @Log(title = "生产异常记录", businessType = BusinessType.INSERT)
    @PostMapping("/exception")
    public AjaxResult add(@RequestBody ProductionAnomalies productionAnomalies)
    {
        return toAjax(productionAnomaliesService.insertProductionAnomalies(productionAnomalies));
    }

    /**
     * 修改生产异常记录
     */
    @RequiresPermissions("production-service:exception:edit")
    @Log(title = "生产异常记录", businessType = BusinessType.UPDATE)
    @PutMapping("/exception")
    public AjaxResult edit(@RequestBody ProductionAnomalies productionAnomalies)
    {
        return toAjax(productionAnomaliesService.updateProductionAnomalies(productionAnomalies));
    }

    /**
     * 删除生产异常记录
     */
    @RequiresPermissions("production-service:exception:remove")
    @Log(title = "生产异常记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/exception/{anomalyIds}")
    public AjaxResult remove(@PathVariable Long[] anomalyIds)
    {
        return toAjax(productionAnomaliesService.deleteProductionAnomaliesByAnomalyIds(anomalyIds));
    }


}
